<!doctype html>
<html>
<head>
    <meta charset="UTF-8"/>
    <title>京东url</title>
    <link rel="stylesheet" type="text/css" href="/webapp/css/easyui.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/icon.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/color.css">
    <link rel="stylesheet" type="text/css" href="/webapp/css/public.css">
    <script type="text/javascript" src="/webapp/js/lib/jquery.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/jquery.global.settings.js"></script>
    <script type="text/javascript" src="/webapp/js/lib/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/webapp/js/common/metadata.js"></script>
    <script type="text/javascript" src="/webapp/js/common/config.js"></script>
</head>
<body>
<div class="easyui-container-fluid">
    <div class="easyui-panel" style="border: none;">
        <div class="nav" id="nav"></div>
        <div class="easyui-panel" style="border:none;">
            <form id="ff">
                <div style="margin-bottom:20px;">

                    <label class="item-label">url：</label>
                    <input type="easyui-textbox" class="easyui-textbox" name="product_url" id="product_url"  />

                    <label class="item-label">品类：</label>
                    <input class="easyui-textbox" style="width:100px;" type="text" name="product_cate"  />

                    <label class="item-label">状态：</label>
                    <input id="entityStatus" class="easyui-switchbutton" checked style="width:80px;height:30px;" onText="启用" offText="禁用"  >

                    <a href="javascript:void(0);" class="easyui-linkbutton c8" onclick="searchBy()" style="width:80px;margin-left: 40px;">查询</a>
                </div>
            </form>
        </div>
        <div class="table-wrapper">
            <table id="datagrid" data-options="fitColumns:true,scrollBarSize:0">
                <thead>
                <tr>
                    <th data-options="field:'product_url',align:'center'" width="300">url</th>
                    <th data-options="field:'product_cate',align:'center'" width="100">品类</th>
                    <th data-options="field:'entityStatus',align:'center',formatter:statusFormatter" width="100">状态</th>
                    <th data-options="field:'action',formatter:actions,align:'center'" width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    function initPage() {
        searchBy(1,100);
        aRecords("京东_url","/webapp/pages/product/jd/")
    }
    $(function(){
        var height = $(window).height();
        var nav_height = $("#nav")._outerHeight();
        var ff_height = $("#ff").height();
        var table_height = height-nav_height-ff_height-40;
        $("#datagrid").css("max-height",table_height);
        $("#datagrid").datagrid({
            rownumbers:true,
            pagination:true,
            idField:"id",
            checkOnSelect:false,
            toolbar:[{
                text:'添加品类_url',
                handler:function(){
                    window.parent.addTab("添加品类_url","/webapp/pages/product/jd/add.html");
                }
            }]
        }).datagrid("getPager").pagination({
            onSelectPage:searchBy
        });
        initPage();
    });
    function searchBy(page,size) {
        var dtd = $.Deferred();
        var data = getFormData(document.getElementById("ff"));
        data.product_url=$("#product_url").textbox('getValue');
        var pager = {page:page,size:size};
        if(!size){
            pager['page']= 1;
            pager['size'] = $("#datagrid").datagrid("getPager").pagination("options").pageSize||100;
        }
        var jsonobj = {};
        jsonobj.entityStatus = $("#entityStatus").switchbutton("options").checked==true?"OK":"DISABLE";
        jsonobj = $.extend(true,jsonobj,transfer(data));
        jsonobj = JSON.stringify(jsonobj);
        console.log(jsonobj)
        $.ajax({
            url:config.url + "/jdrules/page?"+transfer2url(pager),
            type:'post',
            data:jsonobj,
            contentType:"application/json;charset=UTF-8",
            dataType:'json',
            xhrFields:{withCredentials:true},
            beforeSend:function () {
                $.messager.progress({
                    title:"请稍等",
                    interval:50,
                    text:"数据加载中..."
                });
            },
            complete:function () {
                $.messager.progress("close");
            },
            success:function (data) {
                $.messager.progress("close");
                if(data){
                    globalData = data;
                    $("#datagrid").datagrid("loadData",data);
                    dtd.resolve();
                }
            },
            error:function (XMLHttpRequest,textStatus,errorThrown) {

            }
        });
        return dtd.promise();
    }
</script>
<script type="text/javascript">
    function actions(val, row){
        var disableBtnText = row.entityStatus=='OK'?'禁用':"启用";
        return "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' "+
            "style='width:60px;' onclick='edit(\""+row.id+"\",\""+row.categoryCode+"\")'>修改</a>&nbsp;&nbsp;"+
            "<a href='javascript:void(0);' class='easyui-linkbutton l-btn l-btn-small' style='width:60px;' onclick='updateStatus(\""+row.id+"\", \"" + row.entityStatus +"\", \""
            + row.code +"\", \"" + row.brandCode +"\", \"" + row.categoryCode + "\")'>"+disableBtnText+"</a>";
    }
    function edit(id,categoryCode){
        window.parent.addTab("修改", "/webapp/pages/product/jd/add.html?id="+id);
    }
    function updateStatus(id,entityStatus){
        $.messager.confirm("提示","您确定启用型号吗？",function (f) {
            if(f){
                $.ajax({
                    url:config.url+"/jdrules/"+id,
                    type:"DELETE",
                    dataType:"json",
                    data:JSON.stringify(id),
                    contentType:"application/json;charset=UTF-8",
                    xhrFields:{withCredentials:true},
                    beforeSend:function () {
                        $.messager.progress({
                            title:"请稍等",
                            interval:50,
                            text:"操作进行中..."
                        });
                    },
                    complete:function () {
                        $.messager.progress("close");
                        $.messager.alert("提示","操作成功","info",function () {
                            searchBy(1,100);
                        });
                    },
                    success:function (data) {
                        $.messager.alert("提示","操作成功","info",function () {
                            searchBy(1,100);
                        });
                    },
                    error:function (data) {

                    }
                });
            }
        });
    }
    $("#ff").keydown(function (event) {
        var e = event || window.event;
        var keyCode = e.keyCode || e.which;
        if(keyCode=="13"){
            searchBy();
        }
    });

</script>

</html>
